package com.dai.chun.dao.action;

import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.dai.chun.dao.dao.JobDao;
import com.dai.chun.dao.impl.JobDaoImpl;
import com.dai.chun.dao.model.Department;
import com.dai.chun.dao.model.Job;
import com.dai.chun.util.PageSplitUtil;

public class JobAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JobDao jobDao;
	private Job job;
	private List<Job> jobList;
	private PageSplitUtil psu;
	private Department department;
	
	//添加
	public String addJob() throws IOException, SQLException{
		jobDao=new JobDaoImpl();
		job.setJob_setup_time( new SimpleDateFormat("yyyy-MM-dd").format(new Date()) );
		jobDao.save(job);
		return "addJob";
	}
	
	public String listJob() throws IOException, SQLException{
		jobDao=new JobDaoImpl();
		if(psu==null){
			psu=new PageSplitUtil(1);
		}
		psu.comput();
		psu.computPageCount(jobDao.findAllCount());
		jobList=jobDao.listJob(psu);
		return "listJob";
	}
	public String listJobByDeptId() throws IOException, SQLException{
		jobDao=new JobDaoImpl();
		if(psu==null){
			psu=new PageSplitUtil(1);
		}
		psu.comput();
		psu.computPageCount(jobDao.findAllCount());
		jobList=jobDao.listJobByDeptId(psu,department.getDept_id());
		return "listByDeptIdJob";
	}
	
	//删除
	public String delJob() throws SQLException{
		jobDao=new JobDaoImpl();
		jobDao.delJob(job.getJob_id());
		return "delJob";
	}
	
	//修改
	public String updateJob() throws SQLException{
		jobDao=new JobDaoImpl();
		jobDao.updateJob(job);
		return "updateJob";
	}
	
	public String showUpdateJob() throws SQLException{
		jobDao=new JobDaoImpl();
		job=jobDao.findJobById(job.getJob_id());
		return "showUpdateJob";
	}
	
	
	public List<Job> getJobList() {
		return jobList;
	}
	public void setJobList(List<Job> jobList) {
		this.jobList = jobList;
	}
	
	public Job getJob() {
		return job;
	}
	public void setJob(Job job) {
		this.job = job;
	}

	public PageSplitUtil getPsu() {
		return psu;
	}

	public void setPsu(PageSplitUtil psu) {
		this.psu = psu;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

}
